#include "CampaignItem.h"
#include "Defines.h"
#include "Item.h"


#include <QCoreApplication>



QList<CampaignItem*> CampaignItem::c_campaigns = QList<CampaignItem*>();



CampaignItem::CampaignItem(const QString& name, QObject *parent) :
    ItemGroup(name, parent)
{
    setData(CategoryData, ItemCategory_Root);

#if 0
    for (int i = 0; i < 4; i ++)
    {
        ItemGroup* group = new ItemGroup(QString("ItemGroup %1").arg(i), this);
        Item* item = new Item(QString("Item %1").arg(i), group);
    }
#endif

    m_model = new ItemModel(this, this);
    m_dirty = false;

    connect(this, SIGNAL(sigDirty()), this, SLOT(setDirty()));

    connect(m_model.data(), SIGNAL(sigChanged()), this, SLOT(onModelChanged()));
}



CampaignItem* CampaignItem::add(const QString &name)
{
    CampaignItem* campaign = new CampaignItem(name, qApp);
    c_campaigns.append(campaign);

    return campaign;
}



CampaignItem* CampaignItem::take(const QString &name)
{
    foreach (CampaignItem* item, c_campaigns)
    {
        if (!item || item->name() != name) continue;

        return c_campaigns.takeAt(c_campaigns.indexOf(item));
    }

    return 0;
}



QList<CampaignItem*> CampaignItem::campaigns()
{
    return c_campaigns;
}



CampaignItem* CampaignItem::campaign(const QString &name)
{
    foreach (CampaignItem* item, c_campaigns)
    {
        if (!item || item->name() != name) continue;

        return c_campaigns.at(c_campaigns.indexOf(item));
    }

    return 0;
}



ItemModel* CampaignItem::model() const
{
    return m_model.data();
}



void CampaignItem::setFilePath(const QString &file_path)
{
    m_filePath = file_path;
}



QString CampaignItem::filePath() const
{
    return m_filePath;
}


void CampaignItem::setDirty(const bool &dirty)
{
    m_dirty = dirty;
}


bool CampaignItem::isDirty() const
{
    return m_dirty;
}


void CampaignItem::onModelChanged()
{
    setDirty(true);
}


void CampaignItem::setCustomData(const int &, const QVariant &)
{
}


QVariant CampaignItem::customData(const int &) const
{
    return QVariant();
}
